/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 data_lock.h

	$Header: /heroes4/data_lock.h $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "data_lock.h"

#define WIN32_LEAN_AND_MEAN
// as opposed to fat and bloated?
#define NOMINMAX
#include <windows.h>

struct t_data_lock::t_data
{
	CRITICAL_SECTION section;
};

// ------------------------------------------------------------------
// critical section wrapper class.  Atomic locking and unlocking.
// actual data is not in header to avoid use of windows.h
// ------------------------------------------------------------------
t_data_lock::t_data_lock() : m_lock( new t_data )
{
	InitializeCriticalSection( &m_lock->section );
}

// ------------------------------------------------------------------
// critical section wrapper class.  Atomic locking and unlocking.
// actual data is not in header to avoid use of windows.h
// ------------------------------------------------------------------
t_data_lock::~t_data_lock()
{
	DeleteCriticalSection( &m_lock->section );
}

// ------------------------------------------------------------------
// critical section wrapper class.  Atomic locking and unlocking.
// actual data is not in header to avoid use of windows.h
// ------------------------------------------------------------------
void t_data_lock::lock()
{
	EnterCriticalSection( &m_lock->section );
}

// ------------------------------------------------------------------
// critical section wrapper class.  Atomic locking and unlocking.
// actual data is not in header to avoid use of windows.h
// ------------------------------------------------------------------
void t_data_lock::unlock()
{
	LeaveCriticalSection( &m_lock->section );
}
